﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Niknak.Social.Twitter
{
    /// <summary>
    /// Default implementation of IMessage for basic representation of Twitter messages
    /// </summary>
    public class Message : IMessage
    {
        /// <summary>
        /// String representation of the Int64 value
        /// </summary>
        public string MessageId { get; set; }

        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// Indicates if this message is directed at a specific Twitter user
        /// </summary>
        public string InReplyToUserId { get; set; }

        /// <summary>
        /// Indicates if this message is a reply to another Twitter message
        /// </summary>
        public string InReplyToMessageId { get; set; }

        /// <summary>
        /// Typically the device or software used to post the tweet
        /// </summary>
        public string Source { get; set; }

        /// <summary>
        /// If present, the longitude coordinate from the message
        /// </summary>
        public double? Longitude { get; set; }

        /// <summary>
        /// If present, the latitude coordinate from the message
        /// </summary>
        public double? Latitude { get; set; }

        /// <summary>
        /// Plain text content of the tweet
        /// </summary>
        public string Text { get; set; }

        /// <summary>
        /// Entities (URLs, hashtags, pictures and mentions) are parsed into HTML
        /// </summary>
        public string TextAsHtml { get; set; }

        private User _Author { get; set; }
        public IUser Author
        {
            get { return _Author; }
            set { _Author = (User)value; }
        }

        private Message _RetweetedMessage { get; set; }
        /// <summary>
        /// If this message is a retweet then this property contains the original message
        /// </summary>
        public IMessage RetweetedMessage
        {
            get { return _RetweetedMessage; }
            set { _RetweetedMessage = (Message)value; }
        }

        private Media[] _Media { get; set; }
        /// <summary>
        /// An array of media entities, typically only a single picture
        /// </summary>
        public IMedia[] Media
        {
            get { return _Media; }
            set
            {
                _Media = null;
                if (value != null && value.Any())
                    _Media = value.Cast<Media>().ToArray();
            }
        }
    }
}
